package com.ankicoo.practice.coding;

/**
 * Description:
 *
 * @author : QCYANG
 * @date : 2021/7/20 16:13
 */
public class InitializationBlock {
    int intA;
    int intB;

    public static InitializationBlock initializationblock = new InitializationBlock();
    public InitializationBlock() {
        System.out.println("无参构造器00000000");
    }

    public InitializationBlock(int a) {
        System.out.println("一个参数的构造器");

    }


    {
        intA = 10;
        intB = 15;

        System.out.println("构造初始化块11111");
    }

    {
        System.out.println("构造初始化块22222");
    }

    {

        System.out.println("构造初始化块33333");
    }

    //静态初始化块
    static {
        System.out.println("静态初始化块01010101");
    }

    static {
        System.out.println("静态初始化块0202020202");
    }
    public void method(){
        {
            System.out.println("普通初始化块");
        }
    }

    public static void main(String[] args) {
        InitializationBlock initializationblock = new InitializationBlock();
        initializationblock.method();
        System.out.println("------------");
        //多打印几个对象的目的是：好看出Static静态代码块只执行一次！！！
        InitializationBlock initializationBlock2 = new InitializationBlock();
        //因为静态块是在类的初始化阶段完成的，因此在创建某个类的第二个对象时，该类的静态块就不会执行了
        initializationBlock2.method();
        InitializationBlock initializationBlock3 = new InitializationBlock();
        initializationBlock3.method();
    }
}

